package com.evan.daemon;

import java.util.concurrent.TimeUnit;

/**
 * @author huangzhongliang
 * @time 2023/07/15 20:23
 */
public class DaemonTryTwo {
    //一切方法运行的入口
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "是" + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
            while (Boolean.TRUE) {

            }
        }, "T1");
        //要在  t1.start();设置
        //因为逻辑不能有误  人家已经是用户线程了，你又改成守护线程?
        t1.setDaemon(true);
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(3L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //Future
        System.out.println(Thread.currentThread().getName() + "线程结束了");
    }

}
